#include "Base\stdafx.h"

#include "Enemy.h"
#include "Scenegraph/GameObject.h"

#include "../../Materials/ColorMaterial.h"
#include "../../Materials/DiffuseMaterial.h"
#include "..\..\Materials\SkinnedDiffuseMaterial.h"

#include "Components/ModelComponent.h"
#include "Components/ParticleEmitterComponent.h"

#include "Content/ContentManager.h"
#include "Physx/PhysxManager.h"
#include "Components/TransformComponent.h"
#include "Physx\PhysxProxy.h"

#include "Graphics\ModelAnimator.h"
#include "Graphics\TextureData.h"

#include "Scenegraph/GameScene.h"

Enemy::Enemy():m_Counter(0)
{
	
}


Enemy::~Enemy(void)
{
	
}

void Enemy::Initialize(const GameContext& gameContext)
{
	auto physX = PhysxManager::GetInstance()->GetPhysics();

	GetTransform()->Translate( m_PathNodes[0] );

	//Material
	auto mat = new SkinnedDiffuseMaterial();
	mat->SetDiffuseTexture(L"./Resources/Textures/EnemyDiff.tga");
	gameContext.pMaterialManager->AddMaterial(mat, 2);

	//Model Component
	auto enemyModel = new ModelComponent(L"./Resources/Meshes/Enemy.ovm");
	enemyModel->SetMaterial(2);

	AddComponent(enemyModel);

	auto pxMat = physX->createMaterial(0, 0, 0);

	auto controller = new ControllerComponent( pxMat,2,2 );
	AddComponent( controller );
}

void Enemy::AddPathNode(float x, float y, float z)
{
	m_PathNodes.push_back( XMFLOAT3(x,y,z) );
	m_TargetNode = m_PathNodes[0];
	m_PreviousNode = m_TargetNode;
}

void Enemy::Respawn()
{
	GetTransform()->Translate(m_PathNodes[ rand() % (m_PathNodes.size() - 1 ) ] );
}

bool Enemy::CanShoot( const GameContext& gameContext )
{
	m_Counter += gameContext.pGameTime->GetElapsed();
	if (m_Counter > 4)
	{
		m_Counter= 0;
		return true;
	}

	return false;
}

